﻿using System;
using System.Diagnostics;
using System.IO;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using NLog;
using NLog.Extensions.Logging;
namespace ZeusCore.Performance.Test
{
    class Program
    {
        static void Main(string[] args)
        {

            MvcTestAction();
        }

        static void DefaultZeusResultExecutorPerformanceAction()
        {
            while (Console.ReadLine() != "q")
            {
                var actionContext = DefaultZeusResultExecutorPerformance.GetActionContext();
                var defaultZeusResultExecutorPerformance = new DefaultZeusResultExecutorPerformance();

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                for (var i = 0; i < 50000; i++)
                {
                    actionContext.HttpContext.Response.Body.Seek(0, SeekOrigin.Begin);
                    actionContext = defaultZeusResultExecutorPerformance.ExecuteAsyncPerformanceTest(actionContext).Result;
                }

                stopwatch.Stop();
                //if (actionContext.HttpContext.Response.Body.CanRead)
                //{
                //    actionContext.HttpContext.Response.Body.Seek(0, SeekOrigin.Begin);
                //    using (var dataReader = new StreamReader(actionContext.HttpContext.Response.Body))
                //    {
                //        Console.WriteLine(dataReader.ReadToEnd());
                //    }
                //}
                Console.WriteLine($"exec time:{stopwatch.ElapsedMilliseconds}");
            }
            Console.WriteLine("please enter any key quit");
            Console.ReadKey();
        }

        static void MvcTestAction()
        {
            var webhostBuilder = WebHost.CreateDefaultBuilder()
                 .UseUrls("http://*:5015/")
                 .UseStartup<MvcStartup>()
                 .UseKestrel()
                 .ConfigureLogging(configure =>
                 {
                     configure.ClearProviders();
                     //configure.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
                 })
                 .Build();
            webhostBuilder.Run();
        }
    }
}
